package com.benjaminwan.read.free.model

data class ItemOption(
    val value: Int,
    val name: String
)

val List<ItemOption>.valueList: List<Int>
    get() = this.map { it.value }

val List<ItemOption>.nameList: List<String>
    get() = this.map { it.name }

val List<ItemOption>.valueArray: Array<Int>
    get() = this.valueList.toTypedArray()

val List<ItemOption>.nameArray: Array<String>
    get() = this.nameList.toTypedArray()

inline fun itemOption(block: ItemOptionBuilder.() -> Unit): ItemOption =
    ItemOptionBuilder().apply(block).build()

@DslMarker
annotation class ItemOptionDsl

@ItemOptionDsl
class ItemOptionBuilder {
    var value: Int = 0

    var name: String = ""

    fun build(): ItemOption = ItemOption(value, name)
}

@ItemOptionDsl
class ListItemOptionAdder : ArrayList<ItemOption>() {
    inline fun itemConfig(block: ItemOptionBuilder.() -> Unit) {
        add(ItemOptionBuilder().apply(block).build())
    }

    fun itemConfig(config: ItemOption) {
        add(config)
    }

    fun listOfItemConfig(configs: List<ItemOption>) {
        addAll(configs)
    }

}

inline fun listOfItemOption(block: ListItemOptionAdder.() -> Unit): List<ItemOption> =
    ListItemOptionAdder().apply(block)